/* @private
 * This is an internal helper class for the calendar views and should not be overridden.
 * It is responsible for the base event rendering logic underlying all views based on a
 * box-oriented layout that supports day spanning (MonthView, MultiWeekView, DayHeaderView).
 */
Ext.define('DutyList.calendar.util.WeekEventRenderer', {

    requires: ['Ext.core.DomHelper'],

    statics: {
        // private
        getSheduleCell: function(dt,night,id) {
            var cell = id + '-day-' + Ext.Date.format(dt, 'Ymd') + (night ? '-nighttime' : '-daytime');
            /*Ext.each(Ext.select('div').elements,function(qe){
                console.log(qe? qe.id :'');
            }); */
            return Ext.get(cell);
        },

        render: function(o) {
            var wk = 0,
                grid = o.sheduleGrid,
                dttmp = Ext.Date.clone(o.viewStart),
                sheduleTpl = o.tpl,
                weekCount = o.weekCount < 1 ? 6: o.weekCount,
                dayCount = o.weekCount == 1 ? o.dayCount: 7,
                cellCfg;
            for (; wk < weekCount; wk++) {
                if (!grid[wk] || grid[wk].length == 0) {
                    dttmp = DutyList.calendar.util.Date.add(dttmp, {days: 7});
                } else {
                    var dy = 0;
                    for (; dy < dayCount; dy++) {
                        if (grid[wk][dy]) {
                            var ev = 0,
                                cntEvnts = grid[wk][dy].length;
                            for (; ev < cntEvnts; ev++) {
                                var evt = grid[wk][dy][ev];
                                if (!grid[wk][dy][ev]) {
                                    continue;
                                }
                                var item = evt.data || evt.shedule.data;
                                item._night = item[DutyList.calendar.data.SheduleMappings.Night.name];
                                var cell = this.getSheduleCell(dttmp,item[DutyList.calendar.data.SheduleMappings.Night.name],o.id);
                                var newEvnt = Ext.core.DomHelper.append(cell, sheduleTpl.apply(o.templateDataFn(item)));
                                //

                            }
                        }
                        dttmp = DutyList.calendar.util.Date.add(dttmp, {days: 1});
                    }
                }
            }
        }
    }
});